import { Injectable } from '@angular/core';
import 'rxjs/add/operator/toPromise';
import { SafeUrlPipe } from '../pipe/safeUrl.pipe';
import { Headers, Http, RequestOptions } from '@angular/http';

@Injectable()
export class BurnDeviceService {

/*  private burnsubUrl = 'http://192.168.1.102:3000/info_burning';*/

 private burnsubUrl = 'http://192.168.9.108:3000/info_burning';


/*  private burnsubUrl = 'http://localhost:3000/post';*/

  time: string;
  weekday: string;

/*  hh: number;
  mm: number;
  ss: number;*/

  constructor(private http: Http) { }

  getipaddress(): string {
    return '192.168.1.11';
  }

  getmask(): string {
    return '255.255.255.0';
  }
  getnetwork(): string {
    return '192.168.1.1';
  }

  getweek(): string {
    let dataTime = new Date();
   let week = dataTime.getDay();
   switch (week) {
     case 0:
       this.weekday = '星期天';
     break;
     case 1:
       this.weekday = '星期一';
       break;
     case 2:
       this.weekday = '星期二';
       break;
     case 3:
       this.weekday = '星期三';
       break;
     case 4:
       this.weekday = '星期四';
       break;
     case 5:
       this.weekday = '星期五';
       break;
     case 6:
       this.weekday = '星期六';
       break;

   }
    return  this.weekday;
  }

  getminite(minite): string {

   if (minite < 10) {
     return  '0' + minite;
   }
   return minite;
  }
  getsecond(second): string {
    if (second < 10) {
      return  '0' + second;
    }
  }


 gettime(): string {

     let dataTime = new Date();
/*     let hh = dataTime.getHours();
   let mm = dataTime.getMinutes();
   let ss = dataTime.getSeconds();
   this.time = hh + ':' + mm + ':' + ss;*/



/*setTimeout('gettime()', 1000);*/
   return this.time;
  }



  getsubburndata(ipad, mask, net, wek, tim) {
    console.log(ipad + ':' + mask + ':' + net)
    let headers = new Headers({'Content-Type': 'application/json'});
    let options = new RequestOptions({ headers: headers});
    this.http.post(this.burnsubUrl , { ip: ipad , mask: mask , gateway : net, week: wek , time : tim }, options).subscribe(function (data) {
      console.log(data);
    })
  }
}
